/***********************************************
 Lines modified:
 29, 36.
                             lu,xinlai  2008/5/8
***********************************************/

#ifndef _DATA_H_
#define _DATA_H_

//#include "dataselector.h"
#include <vector>
#include <iostream>

using namespace std;
namespace visualization
{

class DataSelector;

class Data
{
	friend class UCDInputFile;
	friend class RayCastRenderer;

private:
	size_t tuple_num;
	size_t tuple_size;
	std::vector<size_t> subtuple_sizes;
	std::vector<size_t> subtuple_offsets;
	std::vector<double> buffer;

/*********************************************
std::vector<std::vector<double>> buffer;
*********************************************/
	// Since both two and three dimensional data
	// field may be considered, so here the dim-
	// ension of the data should be accessed au-
	// tomatically.
	int dataFieldDimension;
	std::vector<double> dataValueAtId;
/*--------------lu,xinlai,2008/5/8------------
*********************************************/

public:
/*********************************************************/
	/*
	*/
	//===================
	size_t getTupleSize()
	{return tuple_size;}
	//===================

	/*
	*/
/*	//==================================
	double *getDataValueAtId(size_t id)
	//==================================
	{
		dataValueAtId.clear();
		
		size_t index = (id - 1) * tuple_size;
*/

	/*	for(size_t i = 0; i < tuple_size; i++)
		{
			dataValueAtId.push_back(buffer[index + i]);
		}
		return &dataValueAtId;
	*/
/*	    return (&(buffer[0]) + index);
	}
*/


//////////////////////////////////////////////////////////////////////
	void getDataValueAtId(size_t id, std::vector<double> &val)
	{
		static int flag = 0;
		size_t index = (id - 1)*tuple_size;
		double *tmp = &(buffer[0]) + index;

		switch(tuple_size)
		{
		case 1:
			//dataValueAtId.push_back(tmp[0]);
			val.push_back(tmp[0]);
			break;		
		case 2:
		{
			for(int itrt = 0; itrt < 2; itrt++)
			{
				//dataValueAtId.push_back(tmp[itrt]);
				val.push_back(tmp[itrt]);
			}
			//dataValueAtId.push_back(0);
			val.push_back(0);
			break;
		}
		case 3:
		{
			for(int itrt = 0; itrt < 3; itrt++)
			{
				//dataValueAtId.push_back(tmp[itrt]);
			    val.push_back(tmp[itrt]);
			}
			break;
		}
		default:
	    {
			static int start, end;
			if(0 == flag)
			{	flag = 1;
				cout << "Something is wrong about the data dimension ..." << endl;
				cout << "There are more than three components for each point data. So you are "
					 << "asked to choose them" << endl;
				cout << "Input the starting data index : " << endl;
				cin >> start;
				cout << "Input the ending data index: " << endl;
				cin >> end;
				cout << "OK! " << endl;
			}
			for(int i = start; i <= end; i++)
			{
				val.push_back(tmp[i]);
			}
		}
		}
	}
/////////////////////////////////////////////////////////////////////////
/*---------------lu,xinlai,2008/5/8------------------------
**********************************************************/
	size_t GetSubTupleSize(size_t i)
	{
		return subtuple_sizes[i];
	}

	size_t GetSubTupleOffset(size_t i)
	{
		return subtuple_offsets[i];
	}

	void PrepareBuffer()
	{
		buffer.reserve(tuple_num * tuple_size);
	}

	bool PushTuple(const std::vector<double> &t);

	void SelectColumn(const DataSelector &selector, 
		std::vector<double> &col, double *min, double *max);

	//void SelectColumnconst DataSelector &selector, 
	//	std::vector<double> &col, double *min, double *max);
};

}

#endif

